<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>SC后台管理系统</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="css/bootstrap.min.css?ver=20180713135642">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="css/all-skins.min.css">
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="plugins/captcha/css/verify.css">
    <script>
        (function () {
            if (!window.Promise) {
                document.writeln('<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"><' + '/' + 'script>');
            }
        })();
    </script>
    <style>
        .form-group {
            margin-bottom: 20px;
        }
    </style>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
</head>
<body class="hold-transition login-page">
<div class="login-box" id="rrapp" v-cloak>
    <div class="login-logo">
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">管理员登录</p>
        <div v-if="error" class="alert alert-danger alert-dismissible">
            <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-triangle"></i> {{errorMsg}}</h4>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="username" placeholder="账号">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" @keydown="keydown" v-model="password"  placeholder="密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
<!--        <div class="form-group has-feedback" >
            <input type="text" class="form-control" v-model="captcha" @keyup.enter="login" placeholder="验证码">
            <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback" >
            <img alt="如果看不清楚，请单击图片刷新！" class="pointer" :src="src" @click="refreshCode">
            &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" @click="refreshCode">点击刷新</a>
        </div>-->
        <div class="form-group has-feedback" >
            <div id="mpanel3" style="margin-top:10px;">
        </div>


        <div class="row">
            <div class="col-xs-8">
                <div class="checkbox icheck">
                </div>
            </div>
            <!-- /.col -->
            <div class="col-xs-4">
                <button type="button"  class="btn btn-primary btn-block btn-flat" @click="login">登录</button>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.social-auth-links -->

    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<script src="libs/jquery.min.js"></script>
<script src="libs/jquery.cookie.js"></script>
<script src="plugins/jqgrid/jquery.jqGrid.min.js"></script>
<script src="libs/vue.min.js"></script>
<script src="libs/bootstrap.min.js"></script>
<script src="libs/app.js"></script>
<script src="js/common.js"></script>

<script src="plugins/captcha/js/crypto-js.js"></script>
<script src="plugins/captcha/js/ase.js"></script>
<script src="plugins/captcha/js/verify.js"></script>
<script type="text/javascript">

    var captchVerify;
    var vm = new Vue({
        el:'#rrapp',
        data:{
            username: '',
            password: '',
            captcha: '',
            error: false,
            errorMsg: '',
            src: 'captcha.jpg'
        },
        beforeCreate: function(){
            if(self != top){
                top.location.href = self.location.href;
            }
        },
        created:function(){

        },
        mounted :function() {
            this.captchaVerify();
        },
        methods: {
            refreshCode: function(){
                this.src = "captcha.jpg?t=" + $.now();
            },
            captchaVerify:function(){
                // // 初始化验证码  弹出式
                $('#mpanel3').pointsVerify({
                    baseUrl:'http://captchapi.netlink.fun',
                    //baseUrl:'http://192.168.0.100:8080',
                    mode:'fixed',
                    imgSize : {
                        width: '315px',
                        height: '150px',
                    },
                    ready : function() {
                    },
                    success : function(params,_this) {
                        //console.log(params,"params1111111111");
                        //返回的二次验证参数 合并到验证通过之后的逻辑 参数中回传服务器
                        captchVerify = _this;
                        vm.captcha = params.captchaVerification;
                        //vm.test();

                    },
                    error : function() {
                    }

                });

            },
            test:function (){
                $.ajax({
                    url:'http://192.168.0.100:8080/auth/verify',
                    type : "POST",
                    data :{"captchaVerification":vm.captcha},
                    success:function(res){
                        //console.log(res,"params222222222");
                    },
                    fail: function(err) {
                        //console.log(err,"err2222222222222222222222");
                    }
                })

            },
            login: function () {
                var data = "username="+vm.username+"&password="+vm.password+"&captcha="+urlencode(vm.captcha);
                $.ajax({
                    type: "POST",
                    url: baseURL + "sys/login",
                    data: data,
                    dataType: "json",
                    success: function(ret){
                        if(ret.code == 0){//登录成功
                            if(ret.eagle2fa==="false" || 1==1){
                                localStorage.setItem("token", ret.token);
                                parent.location.href ='index.html';
                                return;
                            }
                            $.cookie("tempToken",ret.tempToken);
                            $.cookie("tgNum",ret.tgNum);
                            $.cookie("userName",ret.userName);
                            parent.location.href ='glogin.html';
                        }else{
                            vm.error = true;
                            vm.errorMsg = ret.msg;
                            captchVerify.refresh();
                        }
                    }
                });
            },

            keydown : function(e){
                var ev = document.all ? window.event : e;
                if(ev.keyCode==13) {
                    vm.login();
                }

            }
        }
    });

    function urlencode (str) {
        str = (str + '').toString();

        return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
        replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
    }

</script>
</body>
</html>
